/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hype;

import java.util.ArrayList;
import simhya.matheval.Expression;


/**
 *
 * @author Luca
 */
public class AtomicReset {
    String variable;
    boolean local;
    Expression reset;


    
    public AtomicReset(String variable, boolean local, Expression reset) {
        this.variable = variable;
        this.local = local;
        this.reset = reset;
    }

    @Override
    public String toString() {
        if (local)
            throw new HypeException("Trying to convert to String a local atomic reset! Instantiate local variables first");
        String s = "";
        s += variable + " = " + reset.toString();
        return s;
    }


    /**
     * substitutes local variables to a parameterized atomic reset!
     * @param localVariables
     * @param globalSymbols
     * @param isConstant an arraylist containing true if the globalsymbol is a constant!
     * @return
     */
    public AtomicReset substitute(ArrayList<String> localVariables, ArrayList<String> globalSymbols, ArrayList<Boolean> isConstant) {
        String newVariable;
        Expression newReset;
        if (!local) 
            return this;
        if (localVariables.contains(this.variable)) {
            int i = localVariables.indexOf(variable);
            if (isConstant.get(i))
                 throw new HypeException("Trying to instantiate the reset variable " + variable + " by a parameter: " + globalSymbols.get(i));
            newVariable = globalSymbols.get(i);
        } else
            newVariable = variable;
        newReset = reset.substitute(localVariables, globalSymbols);
        return new AtomicReset(newVariable,false,newReset);
    }



}
